package Controler;

import java.util.ArrayList;

import Client.BusinessImplements;
import Client.ClientConsole;
/**
 * 
 * @author Lucie
 *class Add_new_Author_controler
 *Class variables:msg,flag
 *Class methods:get_data,check_input,String get_msg,set_msg
 */
public class Add_new_Author_controler {
	private String msg; 
	private boolean flag;
	
	/**
	 * Constructor initializes the class variables
	 */
	public Add_new_Author_controler ()
	{
		flag=true;
		msg=new String();
		msg=null;
	}
	/**
	 * 
	 * @return String white all of the problems that occurred in the class
	 */
	public String get_msg()
	{
		return msg;
	}
	/**
	 * 
	 * @param new_msg
	 * This method chain messages into a string ,
	 *  the purpose ultimately is to display on the screen all the failures
	 */
	public void set_msg(String new_msg)
	{
		if (msg==null)
			msg=new_msg;
		else
		msg+=new_msg;
		
	}
	/**
	 * this  method call the class ;serverproxy, to Contact with the server,
	 * first we check if author exist in the data base if this method return true 
	 * we can't add new author otherwise we continue and add the author to the db
	 * @param author_name
	 * @return  boolean:If the calls in the method failed it returns false otherwise returns true
	 */
	public boolean get_data(String author_name)
	{
		 ArrayList<String> str_check= new  ArrayList<String>();
		 ArrayList<String> str_author=new  ArrayList<String>();
		
		 
		 check_input( author_name);
		 if (flag==false)
			 return false;
		 
		 str_check=BusinessImplements.GetInstance().getServerProxy().check_author_exist( author_name);
		 
		 if (str_check.get(0).equals("true"))
		 {
			 set_msg("\nauthor allready exist in the system"); 
			 return false;
		 }
		 
		 
		 str_author=BusinessImplements.GetInstance().getServerProxy().add_Author(author_name);
		 if (str_author.get(0).equals("false"))
		 {
			 set_msg("\nsomthing went wrong try again"); 
			 return false;
		 }
			return flag;
	}
/**
 * This method checks the parameters we have received are not empty
 * if they are poses flag= false;
 * @param author
 */
	public void check_input(String author)
	{
		
		if(author.equals(""))
		{
			set_msg("\nmising author name ");
			flag=false;
		}
		
	
		
	}




	



	


	 

}
